//
//  DDEditInvoiceListView.swift
//  DingDongZP
//
//  Created by 三秒文化 on 2016/10/21.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class DDEditInvoiceListView: LDBaseView {

  
    
    var contentView:UIView?
    var isCanEdit = false {
        didSet{
//            configureOfTextField(isCanEdit)
        }
    }
    var descLabArr = [UITextField]()
    
    //默认title
    private var listTitleArr = ["发票抬头","联系人","联系方式","所在地区","详细地址"]
    
    //描述数据
    var descTitleArr = [""] {
        
        didSet{
            
            updateUI()
        }
    }
    
    private let originY:CGFloat = 0
    private let titleFieldW:CGFloat = LDFrame.ScreenWidth - titleW
    private var listH:CGFloat = 45
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func creatLabAndTextField(title:String,desc:String,frameLab:CGRect,frameField:CGRect,isLine:Bool) -> UITextField {
        
        let lab = UILabel.setDetailsLab(title, fontSize: 14, titleColor: LDFontColor.Black, Alignment: .Left)
        let labField = UITextField.init()
        

        labField.rightView? = UIImageView.init(image: UIImage.init(named: "common_line_sure"))
        
        labField.font = LDFont.Font14
        labField.textColor = LDFontColor.LightGray
        
        let bottomLine = UIView()
        bottomLine.backgroundColor = LDLineColorLightGray
        
        lab.frame = frameLab
        labField.frame = frameField
        
        addSubview(lab)
        addSubview(labField)
        
        
//        if isLine == true {
//            
//            bottomLine.frame = CGRectMake(0, frameLab.origin.y + frameLab.size.height - 0.5, LDFrame.ScreenWidth, 0.5)
//            lab.addSubview(bottomLine)
//            labField.addSubview(<#T##view: UIView##UIView#>)
//        }
        
        
        return labField
    }
    
    func updateUI() {
        
        var i = 0
        
        for item in descLabArr {
            
            item.text = descTitleArr[i]
            i += 1
        }
    }
    
    func getH() -> CGFloat {
        
        return listH * CGFloat(listTitleArr.count)
    }
    
    func initUI() {
        
        contentView = UIView()
        contentView?.backgroundColor = LDGolbalColor.White
        addSubview(contentView!)
        
        
        var Y:CGFloat = originY
        
        for i in 0..<listTitleArr.count {
            
            
            let frameLab = CGRectMake(leftMargin, Y, titleW, 35)
            let frameField = CGRectMake(LDMargin_V + titleW, Y, titleFieldW, 35)
            
            
            let isLine = true
            
            let textField = creatLabAndTextField(listTitleArr[i], desc: listTitleArr[i], frameLab: frameLab, frameField: frameField,isLine: isLine)
            
            Y += listH
            descLabArr.append(textField)
        }
    }

}
